-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Resolve: refactor define
into define_local
and define_extern
#143884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Resolve: refactor define
into define_local
and define_extern
#143884
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Conflicts must be resolved in Petrochenkov's PRs, I think. I can then rebase off that. |
resolve: Use interior mutability for extern module map Module map for extern modules is a lazily populated cache, it's not *significantly* mutable. If some logic in name resolver is parallelized, then this cache can be populated from any thread, and without affecting results of any speculative resolution. Unblocks rust-lang#143884. This is a part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747). cc `@LorrensP-2158466`
Rollup merge of #143550 - petrochenkov:lessmutres, r=lcnr resolve: Use interior mutability for extern module map Module map for extern modules is a lazily populated cache, it's not *significantly* mutable. If some logic in name resolver is parallelized, then this cache can be populated from any thread, and without affecting results of any speculative resolution. Unblocks #143884. This is a part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747). cc `@LorrensP-2158466`
8515b3c
to
1296920
Compare
This comment has been minimized.
This comment has been minimized.
89cf98b
to
4497a13
Compare
I couldn't find any more |
define
into define_local
and define_extern
define
into define_local
and define_extern
resolve: Make disambiguators for underscore bindings module-local Disambiguators attached to underscore name bindings (like `const _: u8 = something;`) do not need to be globally unique, they just need to be unique inside the module in which they live, because the bindings in a module are basically kept as `Map<BindingKey, SomeData>`. Also, the specific values of the disambiguators are not important, so a glob import of `const _` may have a different disambiguator than the original `const _` itself. So in this PR the disambiguator is just set to the current number of bindings in the module. This removes one more piece of global mutable state from resolver and unblocks rust-lang#143884.
resolve: Use interior mutability for extern module map Module map for extern modules is a lazily populated cache, it's not *significantly* mutable. If some logic in name resolver is parallelized, then this cache can be populated from any thread, and without affecting results of any speculative resolution. Unblocks rust-lang/rust#143884. This is a part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747). cc `@LorrensP-2158466`
This comment was marked as resolved.
This comment was marked as resolved.
resolve: Make disambiguators for underscore bindings module-local Disambiguators attached to underscore name bindings (like `const _: u8 = something;`) do not need to be globally unique, they just need to be unique inside the module in which they live, because the bindings in a module are basically kept as `Map<BindingKey, SomeData>`. Also, the specific values of the disambiguators are not important, so a glob import of `const _` may have a different disambiguator than the original `const _` itself. So in this PR the disambiguator is just set to the current number of bindings in the module. This removes one more piece of global mutable state from resolver and unblocks rust-lang#143884.
Rollup merge of #144013 - petrochenkov:disambunder, r=oli-obk resolve: Make disambiguators for underscore bindings module-local Disambiguators attached to underscore name bindings (like `const _: u8 = something;`) do not need to be globally unique, they just need to be unique inside the module in which they live, because the bindings in a module are basically kept as `Map<BindingKey, SomeData>`. Also, the specific values of the disambiguators are not important, so a glob import of `const _` may have a different disambiguator than the original `const _` itself. So in this PR the disambiguator is just set to the current number of bindings in the module. This removes one more piece of global mutable state from resolver and unblocks #143884.
Rebased and pushed, @rustbot ready. |
@rustbot ready |
&mut self, | ||
parent: Module<'ra>, | ||
ident: Ident, | ||
ns: Namespace, | ||
res: Res, | ||
vis: Visibility<impl Into<DefId>>, | ||
vis: Visibility, // Implicitly local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vis: Visibility, // Implicitly local | |
vis: Visibility, |
This comment is probably not very useful.
parent.underscore_disambiguator.get() | ||
}); | ||
let resolution = &mut *self.resolution(parent, key).borrow_mut(); | ||
if resolution.non_glob_binding.replace(binding).is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if resolution.non_glob_binding.replace(binding).is_some() { | |
if self.resolution(parent, key).borrow_mut().non_glob_binding.replace(binding).is_some() { |
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Resolve: refactor `define` into `define_local` and `define_extern`
resolve: Make disambiguators for underscore bindings module-local (take 2) The difference with rust-lang/rust#144013 can be seen in the second commit. Now we just keep a separate disambiguator counter in every `Module`, instead of a global counter in `Resolver`. This will be ok for parallel import resolution because we'll need to lock the module anyway when updating `resolutions` and other fields in it. And for external modules the disabmiguator could be just passed as an argument to `define_extern`, without using any cells or locks, once rust-lang/rust#143884 lands. Unblocks rust-lang/rust#143884.
This comment has been minimized.
This comment has been minimized.
@rustbot ready |
Finished benchmarking commit (afc668a): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.8%, secondary -2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 469.891s -> 468.109s (-0.38%) |
assert!(res.opt_def_id().is_none_or(|def_id| !def_id.is_local())); | ||
vis.map_id(|def_id| { | ||
assert!(!def_id.is_local()); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all these asserts can be removed now.
define_extern
is called only from build_reduced_graph_for_external_crate_res
, so the confidence here is high.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think the other added asserts can be also removed now.
Follow up on #143550 and part of #gsoc > Project: Parallel Macro Expansion.
Split up
define
intodefine_local
anddefine_extern
. Refactor usages ofdefine
into either one where it's "correct" (idk if everything is correct atm). Big part of this is thatresolution
can now take a&Resolver
instead of a mutable one.r? @petrochenkov